package com.ruoyi.project.system.messageuser.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.system.messageuser.domain.MessageUser;
import com.ruoyi.project.system.messageuser.service.IMessageUserService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 留言人Controller
 * 
 * @author LCL
 * @date 2021-10-08
 */
@Controller
@RequestMapping("/system/messageuser")
public class MessageUserController extends BaseController
{
    private String prefix = "system/messageuser";

    @Autowired
    private IMessageUserService messageUserService;

    @RequiresPermissions("system:messageuser:view")
    @GetMapping()
    public String messageuser()
    {
        return prefix + "/messageuser";
    }

    /**
     * 查询留言人列表
     */
    @RequiresPermissions("system:messageuser:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(MessageUser messageUser)
    {
        startPage();
        List<MessageUser> list = messageUserService.selectMessageUserList(messageUser);
        return getDataTable(list);
    }

    /**
     * 导出留言人列表
     */
    @RequiresPermissions("system:messageuser:export")
    @Log(title = "留言人", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(MessageUser messageUser)
    {
        List<MessageUser> list = messageUserService.selectMessageUserList(messageUser);
        ExcelUtil<MessageUser> util = new ExcelUtil<MessageUser>(MessageUser.class);
        return util.exportExcel(list, "messageuser");
    }

    /**
     * 新增留言人
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存留言人
     */
    @RequiresPermissions("system:messageuser:add")
    @Log(title = "留言人", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(MessageUser messageUser)
    {
        return toAjax(messageUserService.insertMessageUser(messageUser));
    }

    /**
     * 修改留言人
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        MessageUser messageUser = messageUserService.selectMessageUserById(id);
        mmap.put("messageUser", messageUser);
        return prefix + "/edit";
    }

    /**
     * 修改保存留言人
     */
    @RequiresPermissions("system:messageuser:edit")
    @Log(title = "留言人", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(MessageUser messageUser)
    {
        return toAjax(messageUserService.updateMessageUser(messageUser));
    }

    /**
     * 删除留言人
     */
    @RequiresPermissions("system:messageuser:remove")
    @Log(title = "留言人", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(messageUserService.deleteMessageUserByIds(ids));
    }
}
